﻿
namespace ArtheaEngine.Model
{
    public partial class Affect : IEntity
    {
        public Affect() { }
        public Affect(Flag flag, Ability from, AffectType where, short modifier, short duration)
        {
            Flag = flag;
            Ability = from;
            Duration = duration;
            Modifier = modifier;
            Where = where;
        }

        public override bool Equals(object obj)
        {
            var a = obj as Affect;
            if (a == null)
            {
                return false;
            }
            return Flag == a.Flag && Modifier == a.Modifier && Ability == a.Ability && Where == a.Where;
        }

        public override int GetHashCode()
        {
            return ((int)Flag) + Modifier + Duration + Where.Value;
        }

        public override string ToString()
        {
            string temp;

            if (Where != AffectType.None)
                temp = string.Format(" modifies {0} by {1}", Where.ToString().ToLower(), Modifier);
            else if (Flag)
                temp = string.Format(" adds {0} affect", Flag.ToString(typeof (Affect)));
            else
                temp = string.Empty;

            return string.Format("Spell {0}{1} for {2} hours.",
                                 (Ability == null ? "unknown" : Ability.Name), temp, Duration);
        }
    }

    public partial class ObjectAffect : Affect
    {
         public ObjectAffect(Flag flag, Ability from, AffectType where, short modifier, short duration)
             : base(flag, from, where, modifier, duration)
         {}

         public ObjectAffect() { }
    }

    public partial class CharAffect : Affect
    {

    }

    public partial class AffectTypeWrapper
    {
        public AffectType EnumValue
        {
            get { return (AffectType)Value; }
            set { Value = (int) value; }
        }

        public static implicit operator AffectTypeWrapper(AffectType value)
        {
            return new AffectTypeWrapper { Value = (int)value };
        }

        public static implicit operator AffectType(AffectTypeWrapper value)
        {
            if (value == null) return default(AffectType);

            return value.EnumValue;
        }
    }

    public enum AffectType
    {
        None,
        AC,
        Hit,
        Mana,
        Move
    }
}